<?php

namespace app\common\model;

use think\Model;

class AfterSales extends Model
{
    /** 列表
     * @param $where array
     * @param $page int
     * @param $num int
     * @param $field string
     * @return object
     */
    public static function dataList($where,$page,$num,$field="*",$order="id desc"){
        return self::where($where)
            ->field($field)
            ->order($order)
            ->page($page,$num)
            ->select();
    }

    /** 列表总数统计
     * @param $where array
     * @return int
     */
    public static function dataCount($where){
        return intval(self::where($where)->count());
    }


    public static function afterSalesList($where,$page,$num,$field = 'a.*,o.o_pro_num,o.p_name,p.img as p_img,o.p_num',$order = 'a.id desc'){
        $list = self::alias('a')
            ->field($field)
            ->leftjoin('order o','o.id = a.oid')
            ->leftjoin('product p','p.id = a.pid')
            ->where($where)
            ->order($order)
            ->page($page,$num)
            ->select();
        return $list;
    }

    //售后数
    public static function afterSalesCount($where) {
        return intval(self::alias('a')
            ->field('a.*')
            ->leftjoin('order o','o.id = a.oid')
            ->leftjoin('product p','p.id = a.pid')
            ->where($where)
            ->count());
    }

    /** 详情
     * @param $where array
     * @return object
     */
    public static function dataInfo($where){
        return self::where($where)->find();
    }

    /** 修改
     * @param $data array
     * @return bool
     */
    public static function editInfo($where,$data){
        return self::where($where)->json(['address','commission_info','pay_info'])->update($data);
    }

    /** 数值增加
     * @param $data array
     * @return int
     */
    public static function incInfo($where,$field,$num){
        return self::where($where)->inc($field,$num)->update();
    }
}